<!doctype html>
<html lang="en">
 <head>
<meta charset="UTF-8">
<meta name="Generator">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>设备信息</title>
<link rel="stylesheet" type="text/css" href="/css/intercalate.css" />
<script src="/js/jquery.min.js"></script>
<script src="/js/publick.js"></script>

<style>
.sys_set p{
	width:14rem;
	margin:.8rem auto;
}
</style>
 </head>
 <body>
	<section class="content_infor">
		<section class="sys_set">
			@foreach($deviceList as $device)
			<p class="infor_item">
				@if($device['current'] == 1)
				<span class="on_logo on_active"></span>
				@else
				<span class="on_logo"></span>
				@endif
				<span class="infor_num">{{ $device['device_code'] }}</span>
				<a class="delete_btn" /></a>
			</p>
			@endforeach
		</section>
		<!-- <a class="backing_out" onclick="javascript:history.go(-1);">返回	</a> -->
		<a class="backing_out" onclick="javascript:history.go(-1);">返回</a>
	</section>
	<section class="cutuser_bg">
		<section class="cut_box">
			<p>确定要切换到该设备吗？</p>
			<section class="C_cance_btn" >取消</section>
			<section class="C_ok_btn">确定</section>
		</section>
	</section>
	<section class="undbing_bg">
		<section class="undbing_box">
			<p>确定要解绑该设备吗？</p>
			<section class="cance_btn" >取消</section>
			<section class="ok_btn">确定</section>
		</section>
	</section>
	<!-- 提交信息服务器反馈信息-->
	<section class="hint_bg">
		<section class="hint_box">
			<p class="hint_text"></p>
			<section class="hint_btn">确定</section>
		</section>
	</section>
 </body>
</html>
<script>
$(function(){
	//点击解绑按钮
	$('.delete_btn').click(function(event){
		 event.stopPropagation();
		var _this = $(this);
		$('.undbing_bg').css("display","block");
		$('.undbing_bg').css("height",$(window).height()+"px");
		//点击弹出框"取消"按钮
		$('.cance_btn').unbind('click').click(function(){
			$('.undbing_bg').css("display","none");
		});
		//点击弹出框"确定"按钮
		$('.ok_btn').unbind('click').click(function(){
			$('.undbing_bg').css("display","none");
			var $val_num = $(_this).prev().html();
			$.ajax({
				url:'/api/device/unbind',
				type:'post',
				data:{device_code:$val_num},
				dataType:"json",
				success:function(data){
					if(data.status.errCode == 0){
						$(_this).parent().remove();
						var returnCode = data.data.newDeviceCode;
						var count = $('.infor_item').size();
						if(count == 0){
							window.location.href='/device';
						}
						if(returnCode != null){
							for(var i=0; i<count; i++){
								var originalCode = $('.infor_item').eq(i).children('.infor_num').html();
								if(returnCode==originalCode){
									$('.infor_item').eq(i).children('.on_logo').addClass("on_active");
			    					setTimeout(function(){
			    						window.location.href='/device/index?'+new Date().getTime();
			    					},300);
								}
							}
						}
					}
				}
			});
		})		
	});
	//点击设备信息行切换
	$('.infor_item').click(function(){
		if($(this).children('span').attr('class')!='on_logo'){
			return false;
		}else{
			var _this = $(this);
			$('.cutuser_bg').css("height",$(window).height()+"px");
			$('.cutuser_bg').css("display","block");
			//点击弹出框"取消"按钮
			$('.C_cance_btn').unbind('click').click(function(){
				$('.cutuser_bg').css("display","none");
			});
			var $val_num = $(_this).children('.infor_num').html();
			//点击弹出框"确定"按钮
			$('.C_ok_btn').unbind('click').click(function(){
				$.ajax({
					url:"/api/device/change",
					type:"post",
					data:{device_code:$val_num},
					dataType:"json",
					success:function(data){
						$('.cutuser_bg').css("display","none");
						$(_this).siblings().children('.on_logo').removeClass('on_active');
						$(_this).children('.on_logo').addClass('on_active');
						window.location.href='/device/index?'+new Date().getTime();
					},
					error:function(jqXHR, textStatus, errorThrown){
			    		hint(jqXHR.status);
			    		console.log(jqXHR.status);
			    	}
				});
				
			});	
		}		
	});
	function sendfn($val_num){
		$.ajax({
			url:'/api/device/unbind',
			type:'post',
			data:{device_code:$val_num},
			dataType:"json",
			success:function(){

			}
		});
	}
})
</script>